package mspbots.teams.common;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModel;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;

/**
 * mspbots.data.autotask.utils.ResultResponse
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/7/22
 */
@Data
@NoArgsConstructor
@ApiModel("Request api result entity model")
public class ResultSync implements Serializable {

    private Long tenantId;
    /**
     * Request data id
     */
    @NotEmpty
    private UUID requestId;

    @NotEmpty
    private JsonNode params;

    /**
     * Request date time
     */
    @NotEmpty
    private LocalDateTime time;

    /**
     * Total time to request data, type millisecond
     */
    @NotEmpty
    private long elapsedTime;

    /**
     * Total request data count
     */
    @NotEmpty
    private int count;

    /**
     * Request  status
     */
    @NotEmpty
    private HttpStatus status;

    @NotEmpty
    private String action;

    /**
     * Request result data collection
     */
    @NotEmpty
    private Object msg;

    @Builder
    public ResultSync(Long tenantId, int count, long elapsedTime, HttpStatus status, String action, Object msg) {
        this.count = count;
        this.elapsedTime = elapsedTime;
        this.msg = msg;
        this.status = status;
        this.action = action;
        this.requestId = UUID.randomUUID();
        this.time = LocalDateTime.now();
        this.tenantId = tenantId;
    }

    /**
     * @return default ResultSync body
     */
    public static ResultSync withDefault(String action) {
        return new ResultSync(0L, 0, System.currentTimeMillis(), HttpStatus.OK, action,
                "This request api success.");
    }


}
